home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / time_test.pro < prev    next >
Text File  |  1997-07-08  |  28KB  |  1,010 lines

  1. ; $Id: time_test.pro,v 1.17 1997/02/27 22:10:30 dave Exp $
  2. ;
  3. ; Copyright (c) 1986-1997, Research Systems, Inc.  All rights reserved.
  4. ;       Unauthorized reproduction prohibited.
  5.  
  6. ;    Time test procedure.. Print values of commonly used timings.
  7. pro timer, name    ;Print timing information, name = descriptive
  8. ;    string for message.
  9.  
  10. common timer_common, time, lunno, total_time, geom_time, ntest, demomode
  11.  
  12. t = systime(1)        ;Get current time.
  13. ntest = ntest + 1
  14. tt = t - time
  15. total_time = total_time + tt
  16. geom_time = geom_time + alog(tt)
  17.  
  18. IF (demomode) THEN print, ntest, float(tt), ' ', name $
  19. ELSE printf, lunno, ntest, float(tt), ' ',name
  20.  
  21. time = systime(1)    ;Starting time for next test
  22. end
  23.  
  24. pro init_time,file    ;Initialize timer, file = optional param
  25. ;    containing name of file to write info to
  26. common timer_common, time, lunno, total_time, geom_time, ntest, demomode
  27.  
  28. on_error,2              ;Return to caller if an error occurs
  29.  
  30. total_time = 0.
  31. geom_time = 0.
  32. ntest = 0
  33.  
  34. quiet=!quiet
  35. !quiet=1
  36. demomode=demo_mode()
  37. !quiet=quiet
  38.  
  39. if (n_params(0) ge 1) AND (NOT demomode) then begin
  40.     get_lun, lunno    ;Get a lun
  41.     openw,lunno,file
  42.   end else lunno = -1    ;Set to stdout
  43. time = systime(1)
  44. return
  45. end
  46.  
  47.  
  48.  
  49. pro time_compare, files, outfile, THRESHOLD = threshold
  50. ;Compare results of two time tests...
  51. ; Files = array of file names containing output of each test
  52. ; Outfile = filename for output. If omitted, only output to log window.
  53. ; THRESHOLD = comparison threshold, values outside the range of 1.0
  54. ;     plus or minus threshold are flagged.  Default = 0.15 = 15%.
  55. ; A report is printed..
  56. ;
  57. ; For example:  TIME_COMPARE, FINDFILE('time*.dat'), 'junk.lis'
  58. ;
  59.  
  60. if n_elements(threshold) le 0 then threshold = 0.15
  61.  
  62. nf = n_elements(files)        ;# of files
  63.  
  64. nmax = 100            ;Max number of tests.
  65. t = fltarr(nf, nmax)
  66. names = strarr(nmax)
  67.  
  68. for j=0, nf-1 do begin        ;Read each file
  69.     openr, lun, /get, files(j)
  70.     b = ''
  71.     m = 0            ;Test index
  72.     while not eof(lun) do begin
  73.     readf, lun, b
  74. ;Ignore lines containing "Total Time" and the | character.
  75.         if strpos(b, '|') ge 0 then $
  76.             print, files(j), b, format="(a10, ': ', a)" $
  77.         else if (strpos(b, 'Total Time') lt 0) then begin
  78.         a1 = strcompress(b)
  79.         k = strpos(a1, ' ', 1)
  80.         t(j,m) = float(strmid(a1, k+1, 100))
  81.         k = strpos(a1, ' ', k+1)
  82.         label = strmid(a1, k+1, 100)
  83.         if j eq 0 then names(m) = label $
  84.         else if label ne names(m) then $
  85.         print,'Tests are inconsistent: ', names(m), label
  86.         m = m + 1
  87.         endif
  88.     endwhile
  89.     free_lun, lun
  90. endfor
  91.  
  92. nr = m+1            ;New # of rows
  93. t = t(*,0:nr)            ;Truncate
  94. names = names(0:nr)
  95. t(0,m) = total(t,2)        ;Column sums
  96. names(m) = 'Total Time'
  97. ;        Geometric mean
  98. for i=0, nf-1 do t(i,nr) = exp(total(alog(t(i,0:m-1))) / m)
  99. names(nr) = 'Geometric mean'
  100.  
  101. luns = -1
  102. if n_elements(outfile) gt 0 then begin
  103.     openw, i, /get, outfile
  104.     luns = [luns, i]
  105.     endif
  106. fmt = '(f8.2,'+strcompress(nf)+'i8, 3x,a)'
  107.  
  108. slen = 80 - 12 - 8*nf > 10
  109.  
  110. for file = 0, n_elements(luns)-1 do begin
  111.   printf, luns(file)
  112.   printf, luns(file) , ['Time',strmid(files, 0, 7)], format='(10A8)'
  113.   
  114.   for j=0,nr do begin
  115.      fast = min(t(*,j))
  116.      tt = round(t(*,j) / fast * 100.)
  117.      s = string(fast, tt, strmid(names(j),0,slen-1), format=fmt)
  118.      for k=0, nf-1 do begin
  119.     p  = 8+(k+1)*8        ;Char pos
  120.     if t(k,j) gt (1.0+threshold) * fast then strput, s, '*', p
  121.     if t(k,j) eq fast then strput, s, '^', p
  122.     endfor
  123.      printf, luns(file), s
  124.     endfor
  125.   printf, luns(file), ' '
  126.   printf, luns(file), '^ = fastest.'
  127.   printf, luns(file), '* = Slower by '+strtrim(fix(threshold*100),2) + $
  128.         '% or more.'
  129.   printf, luns(file), systime(0)
  130.   endfor        ;File
  131. if n_elements(outfile) gt 0 then free_lun, luns(1)
  132. end
  133.  
  134.  
  135.  
  136.  
  137.  
  138. pro reset,dummy    ;Reset timer, used to ignore set up times...
  139. ; No-op this procedure to include setup times mainly comprise
  140. ; the time required to allocate arrays and to set them to
  141. ; a given value.
  142.  
  143. common timer_common, time, lunno, total_time, geom_time, ntest, demomode
  144.  
  145. time = systime(1)
  146. return
  147. end
  148.  
  149. pro dummy,dummy
  150. return
  151. end
  152.  
  153.  
  154. pro graphics_times2, filename
  155. ; Time common graphics operations in the same manner as time_test  (REVISED)
  156.  
  157. common timer_common, time, lunno, total_time, geom_time, ntest, demomode
  158.  
  159. on_error,2                      ;Return to caller if an error occurs
  160. if (!d.x_size ne 640) or (!d.y_size ne 512) then $
  161.     window, xs=640, ys=512    ;Use the same size window for fairness.
  162. if n_params() gt 0 then init_time,filename else init_time
  163.  
  164. ; Print header
  165. IF (demomode) THEN BEGIN
  166.     PRINT,'|GRAPHICS_TIMES2 performance for IDL ',!VERSION.RELEASE,' (demo):'
  167.     PRINT,'|       OS_FAMILY=',!VERSION.OS_FAMILY, $
  168.           ', OS=',!VERSION.OS,', ARCH=',!VERSION.ARCH, ' '
  169.     PRINT ,'|    ', systime(0)
  170. ENDIF ELSE BEGIN
  171.     PRINTF,lunno,'|GRAPHICS_TIMES2 performance for IDL ',!VERSION.RELEASE, ':'
  172.     PRINTF,lunno,'|       OS_FAMILY=',!VERSION.OS_FAMILY, $
  173.                  ', OS=',!VERSION.OS,', ARCH=',!VERSION.ARCH, ' '
  174.     PRINTF,lunno,'|    ', systime(0)
  175. ENDELSE
  176.  
  177. for i=1,10 do begin
  178.     plot,[0,1]+i
  179.     empty
  180.     endfor
  181. timer,'Simple plot, 10 times'
  182.  
  183. n = 1000
  184. x = randomu(seed, n) * (2 * !pi)
  185. y = fix((sin(x)+1) * (0.5 * !d.y_vsize))
  186. x = fix((cos(x)+1) * (0.5 * !d.x_vsize))
  187. for i=1,20 do begin
  188.     erase
  189.     empty
  190.     plots,x,y,/dev
  191.     empty
  192.     endfor
  193. timer,strtrim(n,2) + ' vectors x 100'
  194.  
  195. n = 50
  196. plot,[-1,1],[-1,1]
  197.  
  198. for i=3,n do begin
  199.     x = findgen(i) * ( 2 * !pi / i)
  200.     erase
  201.     polyfill,sin(x),cos(x)
  202.     for j=1,i do begin
  203.         xx = randomu(seed, 3)
  204.         yy = randomu(seed, 3)
  205.         polyfill, xx, yy, /norm, color = !d.n_colors/2
  206.         endfor
  207.     empty
  208.     endfor
  209. timer,'Polygon filling'
  210.  
  211. n = 512
  212. a = findgen(n) * (8 * !pi / n)
  213. c = bytscl(sin(a) # cos(a), top = !d.n_colors-1)
  214. d = not c
  215. erase
  216. reset
  217. for i=1,5 do begin
  218.     tv,c
  219.     empty
  220.     tv,d
  221.     empty
  222.     endfor
  223. timer,'Display 512 x 512 image, 10 times'
  224. ;for i=1,10 do begin
  225. ;    c = 0
  226. ;    c = tvrd(0,0,512,512)
  227. ;    endfor
  228. ;timer,'Read back 512 by 512 image, 10 times'
  229.  
  230. IF (demomode) THEN $
  231.   print, float(total_time),'=Total Time, ', $
  232.     exp(geom_time / ntest), '=Geometric mean,',ntest,' tests.' $
  233. ELSE printf, lunno, float(total_time),'=Total Time, ', $
  234.     exp(geom_time / ntest), '=Geometric mean,',ntest,' tests.'
  235.  
  236. if lunno gt 0 then free_lun,lunno
  237. end
  238.  
  239.  
  240.  
  241. pro graphics_times3, filename
  242. ; Time common graphics operations in the same manner as time_test  (REVISED)
  243.  
  244. common timer_common, time, lunno, total_time, geom_time, ntest, demomode
  245.  
  246. on_error,2                      ;Return to caller if an error occurs
  247. if (!d.x_size ne 640) or (!d.y_size ne 512) then $
  248.     window, xs=640, ys=512    ;Use the same size window for fairness.
  249. if n_params() gt 0 then init_time,filename else init_time
  250. a = dist(2)                     ;So we don't get "COMPILED DIST message"
  251.  
  252. ; Print header
  253. IF (demomode) THEN BEGIN
  254.     PRINT,'|GRAPHICS_TIMES3 performance for IDL ',!VERSION.RELEASE,' (demo):'
  255.     PRINT,'|       OS_FAMILY=',!VERSION.OS_FAMILY, $
  256.           ', OS=',!VERSION.OS,', ARCH=',!VERSION.ARCH, ' '
  257.     PRINT,'|    ', systime(0)
  258. ENDIF ELSE BEGIN
  259.     PRINTF,lunno,'|GRAPHICS_TIMES3 performance for IDL ',!VERSION.RELEASE, ':'
  260.     PRINTF,lunno,'|       OS_FAMILY=',!VERSION.OS_FAMILY, $
  261.                  ', OS=',!VERSION.OS,', ARCH=',!VERSION.ARCH
  262.     PRINTF,lunno,'|    ', systime(0)
  263. ENDELSE
  264.  
  265. for i=1,30 do begin
  266.     plot,sin(findgen(100)/(2+i))
  267.     empty
  268.     endfor
  269. timer,'Simple plot, 30 times'
  270.  
  271. n = 1000
  272. x = randomu(seed, n) * (2 * !pi)
  273. y = fix((sin(x)+1) * (0.5 * !d.y_vsize))
  274. x = fix((cos(x)+1) * (0.5 * !d.x_vsize))
  275. for i=1,20 do begin
  276.     erase
  277.     empty
  278.     plots,x,y,/dev
  279.     empty
  280.     endfor
  281. timer,strtrim(n,2) + ' vectors x 100'
  282.  
  283. n = 50
  284. plot,[-1,1],[-1,1]
  285.  
  286. for i=3,n do begin
  287.     x = findgen(i) * ( 2 * !pi / i)
  288.     erase
  289.     polyfill,sin(x),cos(x)
  290.     for j=1,i do begin
  291.         xx = randomu(seed, 3)
  292.         yy = randomu(seed, 3)
  293.         polyfill, xx, yy, /norm, color = !d.n_colors/2
  294.         endfor
  295.     empty
  296.     endfor
  297. timer,'Polygon filling'
  298.  
  299. n = 512
  300. a = findgen(n) * (8 * !pi / n)
  301. c = bytscl(sin(a) # cos(a), top = !d.n_colors-1)
  302. d = not c
  303. erase
  304. reset
  305. for i=1,5 do begin
  306.     tv,c
  307.     empty
  308.     tv,d
  309.     empty
  310.     endfor
  311. timer,'Display 512 x 512 image, 10 times'
  312.  
  313. for i=1,2 do surface, dist(128)
  314. timer,'Surface 128x128, 2 times'
  315.  
  316. for i=1,2 do shade_surf, dist(128)
  317. timer,'Shaded surface 128x128, 2 times'
  318.  
  319.  
  320. erase
  321. nrep = 500
  322. for i=0L, nrep do begin
  323.     siz  = randomn(seed) + 1 > .4
  324.     str = string(byte(randomu(seed, randomu(seed)*20 > 3)*100 + 34))
  325.     xyouts, randomu(seed), randomu(seed), str, charsize=siz, /NORM
  326.     endfor
  327. timer, 'Hershey strings X'+strtrim(nrep,2)
  328.  
  329. erase
  330.  
  331. nrep = 1000
  332. for i=0L, nrep do begin
  333.     str = string(byte(randomu(seed, randomu(seed)*20 > 3)*100 + 34))
  334.     xyouts, randomu(seed), randomu(seed), str, /NORM, /FONT
  335.     endfor
  336. timer, 'Hardware font strings X'+strtrim(nrep,2)
  337.  
  338.  
  339. IF (demomode) THEN $
  340.   print, float(total_time),'=Total Time, ', $
  341.     exp(geom_time / ntest), '=Geometric mean,',ntest,' tests.' $
  342. ELSE printf, lunno, float(total_time),'=Total Time, ', $
  343.     exp(geom_time / ntest), '=Geometric mean,',ntest,' tests.'
  344.  
  345. if lunno gt 0 then free_lun,lunno
  346. end
  347.  
  348. pro time_test2, filename, NOFILEIO=nofileio    ;Time_test revised....
  349.  
  350. ; Why??  This routine is similar to time_test, but with longer and
  351. ; larger tests to obtain more accurate comparisons with ever faster
  352. ; machines.
  353.  
  354. ; As machines have become faster over the years, the time required for
  355. ; some of the individual tests became small in comparison the the
  356. ; resolution of the system clock, making the results inaccurate.  This
  357. ; test is based on the original time_test, but with the interations and
  358. ; data size adjusted to yield times on the order of 5 seconds/test.  
  359.  
  360. ; In a few years, this is written in 1996, the tests will probably
  361. ; have to be again adjusted.
  362.  
  363. common timer_common, time, lunno, total_time, geom_time, ntest, demomode
  364.  
  365. on_error,2                      ;Return to caller if an error occurs
  366.  
  367. nofileio = KEYWORD_SET(nofileio)
  368.  
  369. if n_params() gt 0 then init_time,filename else init_time
  370.  
  371. ; Print header
  372. IF (demomode) THEN BEGIN
  373.     PRINT,'|TIME_TEST2 performance for IDL ',!VERSION.RELEASE,' (demo):'
  374.     PRINT,'|       OS_FAMILY=',!VERSION.OS_FAMILY, $
  375.           ', OS=',!VERSION.OS,', ARCH=',!VERSION.ARCH
  376.     PRINT,'|    ', systime(0)
  377. ENDIF ELSE BEGIN
  378.     PRINTF,lunno,'|TIME_TEST2 performance for IDL ',!VERSION.RELEASE, ':'
  379.     PRINTF,lunno,'|       OS_FAMILY=',!VERSION.OS_FAMILY, $
  380.                  ', OS=',!VERSION.OS,', ARCH=',!VERSION.ARCH
  381.     PRINTF,lunno,'|    ', systime(0)
  382. ENDELSE
  383.  
  384. ;    Empty for loop
  385. nrep = 2000000
  386. for i=1L, nrep do begin & end
  387.  
  388. timer,'Empty For loop,' + string(nrep)+ ' times'
  389.  
  390. for i=1L,100000 do dummy, i
  391. timer,'Call empty procedure (1 param) 100,000 times'
  392.  
  393. ;    Add 100000 scalar ints:...
  394. for i=0L,99999 do a=i+1
  395. timer,'Add 100,000 integer scalars and store'
  396.  
  397. ;    Scalar arithmetic loop:
  398. for i=0L,25000 do begin
  399.     a = i + i -2
  400.     b = a / 2 + 1
  401.     if b ne i then print,'You screwed up',i,a,b
  402.     endfor
  403. timer,'25,000 scalar loops each of 5 ops, 2 =, 1 if)'
  404.  
  405. a=replicate(2b,512,512)
  406. reset
  407. for i=1,10 do b=a*2b
  408. timer,'Mult 512 by 512 byte by constant and store, 10 times'
  409. for i=1,100 do c = shift(b,10,10)
  410. timer,'Shift 512 by 512 byte and store, 100 times'
  411. for i=1,50 do b=a+3b
  412. timer,'Add constant to 512 x 512 byte array and store, 50 times'
  413. for i=1,30 do b=a+b
  414. timer,'Add two 512 by 512 byte images and store, 30 times'
  415.  
  416. a = float(a)
  417. reset
  418. for i=1,30 do b=a*2b
  419. timer,'Mult 512 by 512 floating by constant and store, 30 times'
  420. for i=1,30 do c = shift(b,10,10)    
  421. timer,'Add constant to 512 x 512 floating and store, 40 times'
  422. for i=1,40 do b=a+b
  423. timer,'Add two 512 by 512 floating images and store, 30 times'
  424.  
  425. reset
  426. for i=1,10 do a=randomu(qqq, 150, 150)    ;Random number matrix
  427. timer, 'Generate 225000 random numbers'
  428.  
  429. reset
  430. b = invert(a)
  431. timer,'Invert a 150 by 150 random matrix'
  432.  
  433. reset
  434. ludc, a, index
  435. timer, 'LU Decomposition of a 150 by 150 random matrix'
  436.  
  437. a=bindgen(256,256) & b=a
  438. reset
  439. for i=0,255 do for j=0,255 do b(j,i)=a(i,j)
  440. timer,'Transpose 256 x 256 byte, FOR loops'
  441. for j=1,10 do for i=0,255 do begin
  442.     b(0,i) = transpose(a(i,*))
  443.     end
  444. timer,'Transpose 256 x 256 byte, row and column ops x 10'
  445. for i=1,10 do b=transpose(a)
  446. timer,'Transpose 256 x 256 byte, TRANSPOSE function x 10'
  447.  
  448. a=findgen(100000)+1
  449. c=a
  450. b = a
  451. reset
  452. for i=0L,n_elements(a)-1 do b(i) = alog(a(i))
  453. timer,'Log of 100,000 numbers, FOR loop'
  454. b = alog(a)
  455. timer,'Log of 100,000 numbers, vector ops'
  456.  
  457. n = 2L^17
  458. a = findgen(n)
  459. reset
  460. b = fft(a,1)
  461. b = fft(b,-1)
  462. timer,string(n) + ' point forward plus inverse FFT'
  463.  
  464. a=bytarr(512,512)
  465. a(200:250,200:250)=10b
  466. reset
  467. for i=1,10 do b=smooth(a,5)
  468. timer,'Smooth 512 by 512 byte array, 5x5 boxcar, 10 times'
  469.  
  470. a=float(a)
  471. reset
  472. for i=1,2 do b=smooth(a,5)
  473. timer,'Smooth 512 by 512 floating array, 5x5 boxcar, 2 times'
  474.  
  475. a=bindgen(512,512)
  476. aa =assoc(1,a)
  477. reset
  478. nrecs = 20
  479.  
  480. IF ((NOT demomode) AND (NOT nofileio)) THEN BEGIN
  481.     openw, 1, 'test.dat', 512, initial = 512L*nrecs ;Must be changed for vax
  482.     FOR i=0, nrecs-1 DO aa(i) = a
  483.     FOR i=0, nrecs-1 DO a=aa(i)
  484.     timer, 'Write and read 512 by 512 byte array x '+strtrim(nrecs, 2)
  485.     close, 1
  486. END ELSE BEGIN
  487.     IF (nofileio) AND (NOT demomode) THEN $
  488.           PRINT,'                      Skipped read/write test' $
  489.     ELSE $
  490.           PRINT,'                      Skipped read/write test in demo mode'
  491. ENDELSE
  492.  
  493. IF (demomode) THEN $
  494.   print, float(total_time),'=Total Time, ', $
  495.     exp(geom_time / ntest), '=Geometric mean,',ntest,' tests.' $
  496. ELSE printf, lunno, float(total_time),'=Total Time, ', $
  497.     exp(geom_time / ntest), '=Geometric mean,',ntest,' tests.'
  498.  
  499. ;  Remove the data file
  500. IF ((NOT demomode) AND (NOT nofileio)) THEN BEGIN
  501.     openw, 2, 'test.dat', /DELETE
  502.     close, 2
  503. ENDIF
  504. if lunno gt 0 then free_lun,lunno
  505. end
  506.  
  507. pro time_test3, filename, NOFILEIO=nofileio, FACT=fact
  508.                                 ;Time_test revised....again...
  509.  
  510. ; Why??  This routine is similar to time_test and time_test2, but with
  511. ; longer and larger tests to obtain more accurate comparisons with
  512. ; ever faster machines.
  513.  
  514. common timer_common, time, lunno, total_time, geom_time, ntest, demomode
  515.  
  516. on_error,2                      ;Return to caller if an error occurs
  517.  
  518. nofileio = KEYWORD_SET(nofileio)
  519.  
  520. if n_params() gt 0 then init_time,filename else init_time
  521.  
  522. ; Print header
  523. IF (demomode) THEN BEGIN
  524.     PRINT,'|TIME_TEST3 performance for IDL ',!VERSION.RELEASE,' (demo):'
  525.     PRINT,'|       OS_FAMILY=',!VERSION.OS_FAMILY, $
  526.           ', OS=',!VERSION.OS,', ARCH=',!VERSION.ARCH
  527.     PRINT,'|    ', systime(0)
  528. ENDIF ELSE BEGIN
  529.     PRINTF,lunno,'|TIME_TEST3 performance for IDL ',!VERSION.RELEASE, ':'
  530.     PRINTF,lunno,'|       OS_FAMILY=',!VERSION.OS_FAMILY, $
  531.                  ', OS=',!VERSION.OS,', ARCH=',!VERSION.ARCH
  532.     PRINTF,lunno,'|    ', systime(0)
  533. ENDELSE
  534.  
  535. if n_elements(fact) eq 0 then fact = 1.0 ;Global scale factor for all tests....
  536.  
  537. ;    Empty for loop
  538. nrep = long(2000000 * fact)
  539. for i=1L, nrep do begin & end
  540.  
  541. timer,'Empty For loop, ' + strtrim(nrep,2)+ ' times'
  542.  
  543. nrep = long(100000 * fact)
  544. for i=1L, nrep do dummy, i
  545. timer,'Call empty procedure (1 param) '+strtrim(nrep,2)+ ' times'
  546.  
  547. ;    Add 200000 scalar ints:...
  548. nrep = long(200000 * fact)
  549. for i=1L, nrep do a=i+1
  550. timer,'Add '+strtrim(nrep,2)+' integer scalars and store'
  551.  
  552. ;    Scalar arithmetic loop:
  553. nrep = long(fact * 50000)
  554. for i=1L, nrep do begin
  555.     a = i + i -2
  556.     b = a / 2 + 1
  557.     if b ne i then print,'You screwed up',i,a,b
  558.     endfor
  559. timer, strtrim(nrep,2) + ' scalar loops each of 5 ops, 2 =, 1 if)'
  560.  
  561. a=replicate(2b,512,512)
  562. reset
  563. nrep = long(30L*fact)
  564. for i=1,nrep do b=a*2b
  565. timer,'Mult 512 by 512 byte by constant and store, '+strtrim(nrep,2)+' times'
  566. nrep = long(300L*fact)
  567. for i=1,nrep do c = shift(b,10,10)
  568. timer,'Shift 512 by 512 byte and store, '+strtrim(nrep,2)+' times'
  569.  
  570. nrep = long(100L*fact)
  571. for i=1,nrep do b=a+3b
  572. timer,'Add constant to 512x512 byte array, '+strtrim(nrep,2)+' times'
  573.  
  574. nrep = long(80L*fact)
  575. for i=1, nrep do b=a+b
  576. timer,'Add two 512 by 512 byte arrays and store, '+strtrim(nrep,2)+' times'
  577.  
  578. a = randomu(seed, 512,512)
  579. reset
  580. nrep = long(30L*fact)
  581. for i=1, nrep do b=a*2b
  582. timer,'Mult 512 by 512 floating by constant, '+strtrim(nrep,2)+' times'
  583.  
  584. nrep = long(60L*fact)
  585. for i=1,nrep do c = shift(b,10,10)    
  586. timer,'Shift 512 x 512 array, '+strtrim(nrep,2)+' times'
  587.  
  588. nrep = long(40L*fact)
  589. for i=1, nrep do b=a+b
  590. timer,'Add two 512 by 512 floating images, '+strtrim(nrep,2)+' times'
  591.  
  592. reset
  593. nrep = long(10L*fact)
  594. for i=1, nrep do a=randomu(qqq, 100000L)    ;Random number matrix
  595. timer, 'Generate '+strtrim(100000L*nrep,2)+' random numbers'
  596.  
  597. siz = long(sqrt(fact) * 192)
  598. a = randomu(seed, siz, siz)
  599. reset
  600. b = invert(a)
  601. timer,'Invert a '+strtrim(siz,2)+'^2 random matrix'
  602.  
  603. reset
  604. ludc, a, index
  605. timer, 'LU Decomposition of a '+strtrim(siz,2)+'^2 random matrix'
  606.  
  607. siz = long(384 * sqrt(fact))
  608. a=bindgen(siz,siz) & b=a
  609. reset
  610. for i=0,(siz-1) do for j=0,(siz-1) do b(j,i)=a(i,j)
  611. timer,'Transpose '+strtrim(siz,2)+'^2 byte, FOR loops'
  612. for j=1,10 do for i=0,(siz-1) do begin
  613.     b(0,i) = transpose(a(i,*))
  614.     end
  615. timer,'Transpose '+strtrim(siz,2)+'^2 byte, row and column ops x 10'
  616. for i=1,100 do b=transpose(a)
  617. timer,'Transpose '+strtrim(siz,2)+'^2 byte, TRANSPOSE function x 100'
  618.  
  619. siz = long(100000L*fact)
  620. a=findgen(siz)+1
  621. c=a
  622. b = a
  623. reset
  624. for i=0L, n_elements(a)-1 do b(i) = alog(a(i))
  625. timer,'Log of '+strtrim(siz,2)+' numbers, FOR loop'
  626. for i=1,10 do b = alog(a)
  627. timer,'Log of '+strtrim(siz,2)+' numbers, vector ops 10 times'
  628.  
  629. n = 2L^long(17*fact)
  630. a = findgen(n)
  631. reset
  632. b = fft(a,1)
  633. b = fft(b,-1)
  634. timer,strtrim(n,2) + ' point forward plus inverse FFT'
  635.  
  636. nrep = long(10L*fact)
  637. a=bytarr(512,512)
  638. a(200:250,200:250)=10b
  639. reset
  640. for i=1,nrep do b=smooth(a,5)
  641. timer,'Smooth 512 by 512 byte array, 5x5 boxcar, '+strtrim(nrep,2)+' times'
  642.  
  643. nrep = long(5L*fact)
  644. a=float(a)
  645. reset
  646. for i=1,nrep do b=smooth(a,5)
  647. timer,'Smooth 512 by 512 floating array, 5x5 boxcar, '+strtrim(nrep,2)+' times'
  648.  
  649. a=bindgen(512,512)
  650. aa =assoc(1,a)
  651. reset
  652. nrep = long(40L*fact)
  653.  
  654.  
  655. IF ((NOT demomode) AND (NOT nofileio)) THEN BEGIN
  656.     openw, 1, 'test.dat', 512, initial = 512L*nrep ;Must be changed for vax
  657.     FOR i=0, nrep-1 DO aa(i) = a
  658.     FOR i=0, nrep-1 DO a=aa(i)
  659.     timer, 'Write and read 512 by 512 byte array x '+strtrim(nrep, 2)
  660.     close, 1
  661. END ELSE BEGIN
  662.     IF (nofileio) AND (NOT demomode) THEN $
  663.           PRINT,'                      Skipped read/write test' $
  664.     ELSE $
  665.           PRINT,'                      Skipped read/write test in demo mode'
  666. ENDELSE
  667.  
  668. IF (demomode) THEN $
  669.   print, float(total_time),'=Total Time, ', $
  670.     exp(geom_time / ntest), '=Geometric mean,',ntest,' tests.' $
  671. ELSE printf, lunno, float(total_time),'=Total Time, ', $
  672.     exp(geom_time / ntest), '=Geometric mean,',ntest,' tests.'
  673.  
  674. ;  Remove the data file
  675. IF ((NOT demomode) AND (NOT nofileio)) THEN BEGIN
  676.     openw, 2, 'test.dat', /DELETE
  677.     close, 2
  678. ENDIF
  679. if lunno gt 0 then free_lun,lunno
  680. end
  681.  
  682.  
  683. pro graphics_times, filename
  684. ; Time common graphics operations in the same manner as time_test
  685.  
  686. common timer_common, time, lunno, total_time, geom_time, ntest, demomode
  687.  
  688. on_error,2                      ;Return to caller if an error occurs
  689. if (!d.x_size ne 640) or (!d.y_size ne 512) then $
  690.     window, xs=640, ys=512    ;Use the same size window for fairness.
  691. if n_params() gt 0 then init_time,filename else init_time
  692.  
  693. ; Print header
  694. IF (demomode) THEN BEGIN
  695.     PRINT,'|GRAPHICS_TIMES performance for IDL ',!VERSION.RELEASE,' (demo):'
  696.     PRINT,'|       OS_FAMILY=',!VERSION.OS_FAMILY, $
  697.           ', OS=',!VERSION.OS,', ARCH=',!VERSION.ARCH
  698.     PRINT,'|    ', systime(0)
  699. ENDIF ELSE BEGIN
  700.     PRINTF,lunno,'|GRAPHICS_TIMES performance for IDL ',!VERSION.RELEASE, ':'
  701.     PRINTF,lunno,'|       OS_FAMILY=',!VERSION.OS_FAMILY, $
  702.                  ', OS=',!VERSION.OS,', ARCH=',!VERSION.ARCH
  703.     PRINTF,lunno,'|    ', systime(0)
  704. ENDELSE
  705.  
  706. for i=1,10 do begin
  707.     plot,[0,1]+i
  708.     empty
  709.     endfor
  710. timer,'Simple plot, 10 times'
  711.  
  712. n = 1000
  713. x = randomu(seed, n) * (2 * !pi)
  714. y = fix((sin(x)+1) * (0.5 * !d.y_vsize))
  715. x = fix((cos(x)+1) * (0.5 * !d.x_vsize))
  716. for i=1,5 do begin
  717.     erase
  718.     empty
  719.     plots,x,y,/dev
  720.     empty
  721.     endfor
  722. timer,'vectors'
  723.  
  724. n = 24
  725. plot,[-1,1],[-1,1]
  726.  
  727. for i=3,n do begin
  728.     x = findgen(i) * ( 2 * !pi / i)
  729.     erase
  730.     polyfill,sin(x),cos(x)
  731.     empty
  732.     endfor
  733. timer,'Polygon filling'
  734.  
  735. n = 512
  736. a = findgen(n) * (8 * !pi / n)
  737. c = bytscl(sin(a) # cos(a), top = !d.n_colors-1)
  738. d = not c
  739. erase
  740. reset
  741. for i=1,5 do begin
  742.     tv,c
  743.     empty
  744.     tv,d
  745.     empty
  746.     endfor
  747. timer,'Display 512 x 512 image, 10 times'
  748. ;for i=1,10 do begin
  749. ;    c = 0
  750. ;    c = tvrd(0,0,512,512)
  751. ;    endfor
  752. ;timer,'Read back 512 by 512 image, 10 times'
  753.  
  754. IF (demomode) THEN $
  755.   print, float(total_time),'=Total Time, ', $
  756.     exp(geom_time / ntest), '=Geometric mean,',ntest,' tests.' $
  757. ELSE printf, lunno, float(total_time),'=Total Time, ', $
  758.     exp(geom_time / ntest), '=Geometric mean,',ntest,' tests.'
  759.  
  760. if lunno gt 0 then free_lun,lunno
  761. end
  762.  
  763.  
  764.  
  765. pro time_test, filename, NOFILEIO=nofileio    ;Run some time tests.
  766. ; filename = name of listing file or null for terminal output.
  767. ; nofileio = The presence of this keyword means that no file I/O should be 
  768. ;            done in the test.  Results from demo mode may be compared to 
  769. ;            those from full IDL.
  770. ;
  771. ;+
  772. ; NAME:
  773. ;    TIME_TEST
  774. ;
  775. ; PURPOSE:
  776. ;    General purpose IDL benchmark program that performs
  777. ;    approximately 20 common operations and prints the time
  778. ;    required.
  779. ;
  780. ; CATEGORY:
  781. ;    Miscellaneous.
  782. ;
  783. ; CALLING SEQUENCE:
  784. ;    TIME_TEST [, Filename]
  785. ;
  786. ; OPTIONAL INPUTS:
  787. ;    Filename:    The string containing the name of output file for the 
  788. ;        results of the time test.
  789. ;
  790. ; KEYWORD PARAMETERS:
  791. ;    NoFileIO = Optional keyword when set disables file Input/Output
  792. ;    operations.  Results from tests run in demo mode may be compared to
  793. ;    those run in full mode with this keyword set.
  794. ;
  795. ; OUTPUTS:
  796. ;    No explicit outputs.  Results of the test are printed to the screen 
  797. ;    or to a file.
  798. ;
  799. ; OPTIONAL OUTPUT PARAMETERS:
  800. ;    None.
  801. ;
  802. ; COMMON BLOCKS:
  803. ;    TIMER_COMMON
  804. ;
  805. ; SIDE EFFECTS:
  806. ;    Many operations are performed.  Files are written, etc.
  807. ;
  808. ; RESTRICTIONS:
  809. ;    Could be more complete, and could segregate integer, floating
  810. ;    point and file system IO times into separate figures.
  811. ;
  812. ; PROCEDURE:
  813. ;    Straightforward.
  814. ;    See also the procedure GRAPHICS_TEST, in this file, which
  815. ;    times a few of the common graphics operations.
  816. ;
  817. ;    We make no claim that these times are a fair or accurate
  818. ;    measure of computer performance.  In particular, different
  819. ;    versions of IDL were used.
  820. ;
  821. ;    Graphics performance varies greatly, depending largely on the
  822. ;    window system, or lack of thereof.
  823. ;    
  824. ;    Typical times obtained to date include:
  825. ;      (where    Comp.     = computational tests
  826. ;         Graphics  = graphics tests
  827. ;        Geo. Avg. = geometric average)
  828. ;
  829. ; Machine / OS / Memory            Comp.   Geo. Avg.   Graphics Geo. Avg.
  830. ;
  831. ; MicroVAX II, VMS 5.1, 16MB        637     14.4        39.9    6.57
  832. ; MicroVAX II, Ultrix 3.0, 16MB     616     13.9        58.1    8.27
  833. ; Sun 3/110, SunOS 4.0, 12MB        391      8.19       32.0    7.81
  834. ; Sun 3/80, 12MB, 24 bit color      282      6.03       89.3   21.7
  835. ; PC 386 25MHz, 80387, MSDOS, 4MB   276      6.9        29.5    5.94
  836. ; Mips R2030, RISC/os 4.1, 8MB      246      3.67       14.6    2.62
  837. ; VAXStation 3100, VMS 5.1, 16MB    235      5.13       24.3    3.71
  838. ; HP 9000, Model 375, ?? ??         163      4.14       20.8    3.37
  839. ; DecStation 3100, UWS 2.1, 16MB    150      4.00       17.6    3.23
  840. ; 486 33mhz Clone, MS Windows, 8MB   70      1.81       12.9    3.00
  841. ; Sun 4/65, SunOS 4.1, 16MB          66      1.81        7.0    1.64
  842. ; Silicon Graphics 4D/25, ??         51      1.38       19.4    2.44
  843. ; Sun 4/50 IPX, 16MB             40         1.03     7.7    0.80
  844. ; IBM 6000 Model 325 24MB            40      0.87        5.8    1.21
  845. ; HP 9000 / 720 48 MB                20      0.52        5.0    0.70
  846. ; SGI Indigo XS4000, 32MB         20      0.46     2.1    0.44
  847. ; SGI Indigo2, 150Mhz, 32MB         16         0.32        2.4    0.51
  848. ; DEC Alpha 3000/500, 224MB         13      0.30        2.3    0.43
  849. ;
  850. ;
  851. ; MODIFICATION HISTORY:
  852. ;    DMS, 1986.
  853. ;
  854. ;    DMS, Revised July 1990,  Increased the size of arrays and the number
  855. ;        of repetitions to make most of the tests take longer.
  856. ;        This is to eliminate the effect of clock granularity
  857. ;        and to acknowledge that machines are becoming faster.
  858. ;        Many of the tests were made longer by a factor of 10.
  859. ;
  860. ;    MWR, Jan 1995,  Modified to run in demo mode.  All routines except
  861. ;        TIME_COMPARE now run in demo mode.  Added platform and
  862. ;        version information.  Added NoFileIO keyword.
  863. ;-
  864.  
  865. common timer_common, time, lunno, total_time, geom_time, ntest, demomode
  866.  
  867. on_error,2                      ;Return to caller if an error occurs
  868.  
  869. if n_elements(time) eq 0 then begin
  870.    print, 'TIME_TEST is obsolete.'
  871.    print, 'Use the newer, more accurate, TIME_TEST2, contained in this file.'
  872.    endif
  873.  
  874. do_floating = 1    ;Do floating point array tests
  875.  
  876. nofileio = KEYWORD_SET(nofileio)
  877.  
  878. if n_params() gt 0 then init_time,filename else init_time
  879.  
  880. ; Print header
  881. IF (demomode) THEN BEGIN
  882.     PRINT,'|TIME_TEST performance for IDL ',!VERSION.RELEASE,' (demo):'
  883.     PRINT,'|       OS_FAMILY=',!VERSION.OS_FAMILY, $
  884.           ', OS=',!VERSION.OS,', ARCH=',!VERSION.ARCH
  885. ENDIF ELSE BEGIN
  886.     PRINTF,lunno,'|TIME_TEST performance for IDL ',!VERSION.RELEASE, ':'
  887.     PRINTF,lunno,'|       OS_FAMILY=',!VERSION.OS_FAMILY, $
  888.                  ', OS=',!VERSION.OS,', ARCH=',!VERSION.ARCH
  889. ENDELSE
  890.  
  891. ;    Empty for loop
  892. for i=0L, 999999l do begin & end
  893.  
  894. timer,'Empty For loop, 1 million times'
  895.  
  896. for i=1L,100000 do dummy, i
  897. timer,'Call empty procedure (1 param) 100,000 times'
  898.  
  899. ;    Add 100000 scalar ints:...
  900. for i=0L,99999 do a=i+1
  901. timer,'Add 100,000 integer scalars and store'
  902.  
  903. ;    Scalar arithmetic loop:
  904. for i=0L,25000 do begin
  905.     a = i + i -2
  906.     b = a / 2 + 1
  907.     if b ne i then print,'You screwed up',i,a,b
  908.     endfor
  909. timer,'25,000 scalar loops each of 5 ops, 2 =, 1 if)'
  910.  
  911. a=replicate(2b,512,512)
  912. reset
  913. for i=1,10 do b=a*2b
  914. timer,'Mult 512 by 512 byte by constant and store, 10 times'
  915. for i=1,10 do c = shift(b,10,10)
  916. timer,'Shift 512 by 512 byte and store, 10 times'
  917. for i=1,10 do b=a+3b
  918. timer,'Add constant to 512 x 512 byte array and store, 10 times'
  919. for i=1,10 do b=a+b
  920. timer,'Add two 512 by 512 byte images and store, 10 times'
  921.  
  922. if do_floating then begin
  923.     a = float(a)
  924.     reset
  925.     for i=1,10 do b=a*2b
  926.     timer,'Mult 512 by 512 floating by constant and store, 10 times'
  927.     for i=1,10 do c = shift(b,10,10)    
  928.     timer,'Add constant to 512 x 512 floating and store, 10 times'
  929.     for i=1,10 do b=a+b
  930.     timer,'Add two 512 by 512 floating images and store, 10 times'
  931.     endif
  932.  
  933.  
  934. a=randomu(qqq,100,100)    ;Random number matrix
  935. reset
  936. b = invert(a)
  937. timer,'Invert a 100 by 100 random matrix'
  938.  
  939. a=bindgen(256,256) & b=a
  940. reset
  941. for i=0,255 do for j=0,255 do b(j,i)=a(i,j)
  942. timer,'Transpose 256 x 256 byte, FOR loops'
  943. for i=0,255 do begin
  944.     b(0,i) = transpose(a(i,*))
  945.     end
  946. timer,'Transpose 256 x 256 byte, row and column ops'
  947. b=transpose(a)
  948. timer,'Transpose 256 x 256 byte, transpose function'
  949.  
  950. a=findgen(100000)+1
  951. c=a
  952. b = a
  953. reset
  954. for i=0L,n_elements(a)-1 do b(i) = alog(a(i))
  955. timer,'Log of 100,000 numbers, FOR loop'
  956. b = alog(a)
  957. timer,'Log of 100,000 numbers, vector ops'
  958.  
  959. for i=0L,n_elements(a)-1 do c(i)=a(i)+b(i)
  960. timer,'Add two 100000 element floating vectors, FOR loop'
  961.  
  962. c=a+b
  963. timer,'Add two 100000 element floating vectors, vector op'
  964.  
  965. a = findgen(65536L)
  966. reset
  967. b=fft(a,1)
  968. timer,'65536 point real to complex FFT'
  969.  
  970. a=bytarr(512,512)
  971. a(200:250,200:250)=10b
  972. reset
  973. b=smooth(a,5)
  974. timer,'Smooth 512 by 512 byte array, 5x5 boxcar'
  975.  
  976. a=float(a)
  977. reset
  978. b=smooth(a,5)
  979. timer,'Smooth 512 by 512 floating array, 5x5 boxcar'
  980.  
  981. IF ((NOT demomode) AND (NOT nofileio)) THEN BEGIN
  982.     a=bindgen(512, 512)
  983.     aa =assoc(1, a)
  984.     reset
  985.     openw, 1, 'test.dat', 512, initial = 5120 ;Must be changed for vax
  986.     FOR i=1, 10 DO aa(0) = a
  987.     FOR i=1, 10 DO a=aa(0)
  988.     timer, 'Write and read 10 512 by 512 byte arrays'
  989.     close, 1
  990. END ELSE BEGIN
  991.     IF (nofileio) AND (NOT demomode) THEN $
  992.           PRINT,'                      Skipped read/write test' $
  993.     ELSE $
  994.           PRINT,'                      Skipped read/write test in demo mode'
  995. ENDELSE
  996.  
  997. IF (demomode) THEN $
  998.   print, float(total_time),'=Total Time, ', $
  999.     exp(geom_time / ntest), '=Geometric mean,',ntest,' tests.' $
  1000. ELSE printf, lunno, float(total_time),'=Total Time, ', $
  1001.     exp(geom_time / ntest), '=Geometric mean,',ntest,' tests.'
  1002.  
  1003. ;  Remove the data file
  1004. IF ((NOT demomode) AND (NOT nofileio)) THEN BEGIN
  1005.     openw, 2, 'test.dat', /DELETE
  1006.     close, 2
  1007. ENDIF
  1008. IF lunno GT 0 THEN free_lun, lunno
  1009. end
  1010.